<?php
namespace app\bbs\controller;

use think\Controller;
use think\Db;

class Classification extends Controller
{
    public function index()
    {
        $head = head('layui-this');
        $main = Db::table('bbs_classification_main')
            ->where('start', 'eq', 0)
            ->select();
        foreach ($main as $key => $value) {
            $main[$key]['son'] = Db::table('bbs_classification_son')
                ->where([
                    'son_class_start' => 0,
                    'main_class_id' => $value['id']
                ])
                ->select();
            foreach ($main[$key]['son'] as $key_son => $value_son) {
                $main[$key]['son'][$key_son]['released_today'] =  Db::table('bbs_article')
                ->where([
                    'class_id' => $value_son['id'],
                    'release_data' => date('Y-m-d'),
                ])
                ->count();
                $main[$key]['son'][$key_son]['All_theme_count'] =  Db::table('bbs_article')
                ->where([
                    'class_id' => $value_son['id'],
                ])
                ->count();
            }
        }
        return $this->fetch('classification', ['head' => $head, 'calss' => $main]);
    }
}
